# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: AlexWMF <alexxwmf@gmail.com>

_realname=qxmpp
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.9.3
pkgrel=1
pkgdesc="Cross-platform C++ XMPP client and server library"
arch=('any')
license=("LGPL")
url="https://github.com/qxmpp-project/qxmpp"
depends=("${MINGW_PACKAGE_PREFIX}-libtheora"
         "${MINGW_PACKAGE_PREFIX}-libvpx"
         "${MINGW_PACKAGE_PREFIX}-qt5"
         "${MINGW_PACKAGE_PREFIX}-speex")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=(!strip staticlibs)
source=("${_realname}-${pkgver}".tar.gz::"https://github.com/qxmpp-project/${_realname}/archive/v${pkgver}.tar.gz")
sha256sums=('13f5162a1df720702c6ae15a476a4cb8ea3e57d861a992c4de9147909765e6de')

build() {
  cd ${srcdir}/${_realname}-${pkgver}

  local _buildpkgdir=${pkgdirbase}/${pkgname}${MINGW_PREFIX}
  mkdir -p ${_buildpkgdir}
  local PREFIX_WIN=$(cygpath -am ${_buildpkgdir})

  ${MINGW_PREFIX}/bin/qmake \
    PREFIX=${PREFIX_WIN} \
    QXMPP_USE_SPEEX=1 \
    QXMPP_USE_THEORA=1 \
    QXMPP_USE_VPX=1 \
    "CONFIG+=release" \
    qxmpp.pro

  make # VERBOSE=1
}

package() {
  cd ${srcdir}/${_realname}-${pkgver}
  make install
  mkdir -p ${pkgdir}${MINGW_PREFIX}/bin/
  mv "${pkgdir}${MINGW_PREFIX}"/lib/*.dll "${pkgdir}${MINGW_PREFIX}"/bin/

  local PREFIX_WIN=$(cygpath -am ${pkgdir}${MINGW_PREFIX})
  local PREFIX_DEP=$(cygpath -am ${MINGW_PREFIX})

  echo "PREFIX_DEP=${PREFIX_DEP}"
  sed -s "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" \
    -i ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/qxmpp.pc
  sed -s "s|${PREFIX_DEP}|${MINGW_PREFIX}|g" \
    -i ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/qxmpp.pc
}
